<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>菜单管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="菜单,管理">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="${CONTEXT_PATH}/common/tree/treeCss.css">
	<script type="text/javascript" src="${CONTEXT_PATH}/common/tree/jquery.simple.tree.js"></script>
	
	<script type="text/javascript">
	
	var x = '';
	
	var simpleTreeCollection;
	$(document).ready(function(){
		simpleTreeCollection = $('#simpleTree').simpleTree({
			drag:false,
			docToFolderConvert:true,
			afterClick:function(node){
				var id = node.attr('id');
				x = id.substring(2);//模块id
			}
		});
	});
	
	
	//添加节点
	function addMenu(val)
	{
		if(!checkInfo())
		{
			return;
		}
		var url = '${CONTEXT_PATH}/inner/menu/toAddMenu.action?menu.id=' + x + '&moduleType=' + val + '&timestamp=' + Date.parse(new Date());
		showMd(url, 550, 250);
	}
	
	
	//判断是否有选中
	function checkInfo()
	{
		var li = $('#li' + x);
		if(li.length < 1)
		{
			showMsg('请先选择节点');
			return false;
		}
		return true;
	}
	
	
	function updateMenu()
	{
		if(!checkInfo())
		{
			return;
		}
		var url = '${CONTEXT_PATH}/inner/menu/toUpdateMenu.action?menu.id=' + x + '&timestamp=' + Date.parse(new Date());
		showMd(url, 550, 250);
	}
	
	function delMenu()
	{
		if(!checkInfo())
		{
			return;
		}
		showConfirm('确认删除？', function(v){
    		if(v == true)
    		{
    			$.ajax({
		    		url:'${CONTEXT_PATH}/inner/menu/delMenu.action?menu.id=' + x,
		    		type:'post',
		    		dataType:'json',
		    		success:
		    			function(result){
		    				if(result == false)
		    				{
			    				showMsg('删除成功。', function(){
			    					simpleTreeCollection.get(0).delNode();
						    	});
					    	}
					    	else
					    	{
					    		showMsg('请先删除子菜单。');
					    	}
		    			}
		    	});
    		}
    	});
	}
	</script>

  </head>
  
  <body style="margin:-22px -22px 0px -22px">
  	
  	<jsp:include page="/jsp/outward/business/common/menuLink.jsp">
 		<jsp:param name="menuLink" value="[{'name':'系统管理'},{'name':'菜单管理'}]"/>
 		<jsp:param name="width" value="40%"/>
 	</jsp:include>
  	<table width="100%" height="90%" cellspacing="0">
  		<tr>
  			<td height="5%" align="left" valign="top">
  			
  				<table cellspacing="0">
			    	<tr>
			    		<my:hasPermission privilegeId="updateMenu">
			    		<td width="100px" align="left">
			    			<input type="button" onclick="updateMenu()" value="修改菜单" class="btn" />
			    		</td>
			    		</my:hasPermission>
			    		<my:hasPermission privilegeId="addNextLevelMenu">
			    		<td width="140px" align="left">
			    			<input type="button" onclick="addMenu('next')" value="新增下级菜单" class="btn2" />
			    		</td>
			    		</my:hasPermission>
			    		<my:hasPermission privilegeId="addSameLevelMenu">
			    		<td width="140px" align="left">
			    			<input type="button" onclick="addMenu('same')" value="新增同级菜单" class="btn2" />
			    		</td>
			    		</my:hasPermission>
			    		<my:hasPermission privilegeId="delMenu">
			    		<td width="100px" align="left">
			    			<input type="button" onclick="delMenu()" value="删除菜单" class="btn" />
			    		</td>
			    		</my:hasPermission>
			    	</tr>
			    </table>
			    
  			</td>
  		</tr>
  		<tr>
  			<td align="left" valign="top" height="95%">
  				<div style="width:100%; height:100%; overflow-y:auto">
  				
  					<ul id="simpleTree" class="simpleTree">
						<li class="root" id="li0"><span>主菜单</span>
							<s:property value="tree" escape="false"/>
						</li>
					</ul>
					
  				</div>
  			</td>
  		</tr>
  	</table>
    
  </body>
</html>
